<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片转为Base64并上传</title>
</head>
<body>

<input type="file" id="hiddenFileInput" style="display: none;">

<button id="uploadButton">选择文件</button>

<script>
    document.getElementById('uploadButton').addEventListener('click', function() {
        var fileInput = document.getElementById('hiddenFileInput');
        var clickEvent = new MouseEvent('click', {
            'view': window,
            'bubbles': true,
            'cancelable': false
        });
        fileInput.dispatchEvent(clickEvent);
    });

    document.getElementById('hiddenFileInput').addEventListener('change', function(e) {
        var file = e.target.files[0];
        // 处理文件...
    });
</script>

</body>
</html>
